#include "NxData.h"
#include "../utils/NxHttp.h"
#include "NxDataFactory.h"

int NJGIS::SERVICE::NjData::isExist()
{
	std::string url;
	this->getBaseUrl(url);
	url = url + "geodata/json/" + this->_id;
	Json::Value jResonese;
	NJGIS::SERVICE::NjHttpHelper::request_get_json_sync(url.c_str(), jResonese);

	if(jResonese["result"].asString() == "suc")
	{
		Json::Value jData = jResonese["data"];
		if(jData.type() == Json::stringValue && jData.asString() == "")
		{
			return false;
		}
		return true;
	}
	return false;
}

const char* NJGIS::SERVICE::NjData::getID()
{
	return this->_id.c_str();
}

const char* NJGIS::SERVICE::NjData::getTag()
{
	return this->_tag.c_str();
}

const char* NJGIS::SERVICE::NjData::getGenarationDateTime()
{
	return this->_genarationDateTime.c_str();
}

NJGIS::SERVICE::NjDataType NJGIS::SERVICE::NjData::getType()
{
	return this->_type;
}

int NJGIS::SERVICE::NjData::getSize()
{
	return this->_size;
}

const char* NJGIS::SERVICE::NjData::getValue()
{
	return this->_value.c_str();
}

int NJGIS::SERVICE::NjData::saveAs( const char* path )
{
	std::string url;
	this->getBaseUrl(url);
	url = url + "geodata/" + this->_id;
	return NJGIS::SERVICE::NjHttpHelper::download(url.c_str(), path);
}